/**
 * 字符串-找出字符串中第一个匹配项的下标-力扣28
 */
public class Practice_21 {
    public static void main(String[] args) {

        int t = strStr("fsadbutsad", "sad");

    }

    public static int strStr(String haystack, String needle) {
        if (needle == null || needle.length() == 0 || haystack == null || haystack.length() == 0) {
            return -1;
        }

        int neeleSize = needle.length();
        int length = haystack.length();

        int i = 0;
        int j = neeleSize - 1;

        if (length < neeleSize) {
            return -1;
        } else {
            while (i <= length - neeleSize) {
                String keystr = (String) haystack.substring(i, j+1);
                if (!keystr.equals(needle)) {
                    i++;
                    j++;
                } else {
                    return i;
                }
            }
        }

        return -1;

    }

}
